<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		
	</head>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		body{
			height: calc(100vh);
			background-image: url(img/backgroud_img.jpg);
			background-size: cover;
		}
	</style>
	<link rel="stylesheet" type="text/css" href="js/layui/css/layui.css"/>
	<script type="text/javascript" src="js/layui/layui.all.js"></script>
	<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<body>
		<div class="layui-container">
			<div  class="layui-row">
				<div class="layui-col-md6 layui-col-lg-offset3" style="margin-top: 100px;">
					<!-- 标题 -->
					<div class="layui-input-block">
						 <div class="title" style="font-size: 2em;text-align: center;"><img src="img/logo.png" >家庭医生签约平台</div>
					</div>	
				</div>
				<div class="layui-col-md6 layui-col-lg-offset3" style="margin-top: 20px;">
					<div class="layui-form">
						<form  action="" method="" class="layui-form ">
							<!-- phone -->
							<div class="layui-form" style="margin: 20px;">
								<label class="layui-form-label">新密码：</label>
								<div class="layui-input-block">
									<input type="password" id="pass1" name="password_1" class="layui-input" lay-verify="required|password" lay-reqtext="密码不能为空" placeholder="请输入新密码" autocomplete="off"  />
								</div>
							</div>
							<!-- 身份证 -->
							<div class="layui-form" style="margin: 20px;">
								<label class="layui-form-label">确认密码：</label>
								<div class="layui-input-block">
									<input type="password" name="password_2" class="layui-input" lay-verify="required|password2" lay-reqtext="确认密码不能为空" placeholder="请确认新密码" autocomplete="off"  />
								</div>
							</div>
							<!-- submit -->
							<div class="layui-form" style="margin: 20px;">
								<div class="layui-input-block">
									<input type="submit"  class="layui-btn"  lay-submit lay-filter="submit_button" style="width: 100% ;background-color: #75c5dc;" value="更改"/>
								</div>
							</div>
						</form>
					</div>
					
					<div class="layui-col-md6 layui-col-lg-offset10" style="margin-top: 10px;">
						<a href="login.html">返回登录<i class="layui-icon layui-icon-right"></i></a>
					</div>
				</div>
			</div>
		</div>
		
		<script src="./js/md5.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var phone_num;
			window.onload = function(){ //跳转过来直接进行电话号码的截取
				var loc = location.href;
				var n1 = loc.length;
				var n2 = loc.indexOf('=');
				phone_num = decodeURI(loc.substr(n2+1,n1-n2));
			};
			
			layui.use(['layer', 'form', 'element'],function(){
				//加载layui表单元素
				var form = layui.form,
					layer = layui.layer,
					element = layui.element; 
				form.render();
				
				form.verify({
					password: [/^[\S]{6,12}$/,'密码必须6到12位，且不能出现空格'],
					password2 : function(value){
						var pass2_value = $("#pass1").val();
						if(pass2_value != value){
							return '两次密码不正确'
						}
					},
				});
				
				form.on("submit(submit_button)", function (data) {
					// console.log(JSON.stringify({
					// 		new_pass : hex_md5(data.field.password_1),
					// 		re_pass : hex_md5(data.field.password_2),
					// 		identify : 'doctor',
					// 		phone : phone_num
					// 	}));
					// 	return false;
					$.ajax({
						url:'http://123.56.67.48:8080/changePassword',
		  			method:'POST',
						contentType:'application/json',
						data:JSON.stringify({
							new_pass : hex_md5(data.field.password_1),
							re_pass : hex_md5(data.field.password_2),
							identify : 'doctor',
							phone : phone_num
						}),
		 					success:function(res){
								if(JSON.parse(res).code == 1){
									console.log("密码更改成功");
									window.location.href = "login.html"
								}
						},              
						error:function (res) {
							console.log("更改失败"); 
							}           
					}); 
					return false;
				});
			});
		</script>
	</body>
</html>